package com.link.base.base.product.controller;


import com.link.base.base.product.model.ProdRcmd;
import com.link.base.base.product.service.ProdRcmdService;
import com.link.base.user.model.CoreUser;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.util.UserUtil;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author unknown
 * @date unknown
 */
@Controller
@RequestMapping("/link/prodRcmd")
public class ProdRcmdController extends BasicController<ProdRcmd> {

    @Resource
    private ProdRcmdService prodRcmdService;

    @Override
    public BasicService<ProdRcmd> getBasicService() throws Exception {
        return prodRcmdService;
    }

    /**
     * 该方法为app迁移过来的方法
     *
     * @param entity
     * @param session
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/queryAllActive")
    @ResponseBody
    public Map<String, Object> queryAllActive(ProdRcmd entity, HttpSession session, HttpServletRequest request,
                                              HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        CoreUser user = UserUtil.getUser();
        // 用户id
        entity.setUserId(user.getId());
        entity.setAcctId(user.getAcctId());
        // 用户类型
        entity.setUserType(user.getEmpType());
        entity.setCorpid(user.getLoginCorpId());
        try {
            List<ProdRcmd> list = prodRcmdService.queryAllActive(entity);
            result.put("success", true);
            result.put("result", list);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", new ArrayList<ProdRcmd>());
            result.put("message", e.getMessage());
        }
        return result;
    }
}
